package com.ysstech.reportworld.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysstech.common.cache.RedisCacheManager;
import com.ysstech.common.entity.PageBean;
import com.ysstech.common.exception.BusinessException;
import com.ysstech.common.service.DicvalueService;
import com.ysstech.common.util.DateUtil;
import com.ysstech.common.util.StringUtil;
import com.ysstech.reportworld.entity.*;
import com.ysstech.reportworld.enums.ReportWorldEnum;
import com.ysstech.reportworld.enums.ReportWorldStatusEnum;
import com.ysstech.reportworld.mapper.TableDetailMapper;
import com.ysstech.reportworld.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lishuangliang
 * @since 2022-04-27
 */
@Service
public class TableDetailServiceImpl extends ServiceImpl<TableDetailMapper, TableDetail> implements TableDetailService {
    @Autowired
    private TableDetailMapper tableDetailMapper;
    @Autowired
    private DicvalueService dicvalueService;
    @Autowired
    private DataCustomerService dataCustomerService;
    @Autowired
    private DataModularService dataModularService;
    @Autowired
    private DataReportService dataReportService;
    @Autowired
    private TableService tableService;
    @Autowired
    private RedisCacheManager redisCacheManager;
    @Autowired
    private TableDetailStandardCheckService tableDetailStandardCheckService;

    /**
     * 获取所有表字段信息
     *
     * @param tableDetail
     * @param pageBean
     * @return
     * @throws Exception
     */
    public PageBean<TableDetail> queryAllDataTableDetail(TableDetail tableDetail, PageBean pageBean) throws Exception {
        TableDetail queryTableDetail = this.getQueryWrapper(tableDetail);
        IPage pageScheduleLog = tableDetailMapper.queryReportTableDetail(new Page<>(pageBean.getPageNum(), pageBean.getPageSize()), queryTableDetail);
        this.switchedListReportDetail(pageScheduleLog.getRecords());
        return new PageBean<>(pageScheduleLog);
    }


    /**
     * 通过表结构id查询表结构明细信息
     *
     * @param tableDetail
     * @return
     * @throws Exception
     */
    public List<TableDetail> queryTableDetailListByTableId(TableDetail tableDetail) throws Exception {
        if (null == tableDetail || StringUtils.isBlank(tableDetail.getTableId())) {
            throw new BusinessException("获取表结构信息失败，请稍后重试！");
        }
        TableDetail queryTableDetail = this.getQueryWrapper(tableDetail);
        List<TableDetail> list = tableDetailMapper.queryReportTableDetail(queryTableDetail);
        this.switchedListReportDetail(list);
        return list;
    }

    /**
     * 获取查询条件
     *
     * @param tableDetail
     * @return
     */
    private TableDetail getQueryWrapper(TableDetail tableDetail) {
        if (StringUtils.isNotBlank(tableDetail.getColumnReport())) {
            List<String> ids = JSONArray.parseArray(tableDetail.getColumnReport(), String.class);
            List<DataReport> list = new ArrayList<>();
            for (String str : ids) {
                DataReport dataReport = new DataReport();
                dataReport.setReportId(str);
                list.add(dataReport);
            }
            tableDetail.setListReport(list);
        }
        if (StringUtils.isNotBlank(tableDetail.getColumnCustomer())) {
            List<String> ids = JSONArray.parseArray(tableDetail.getColumnCustomer(), String.class);
            List<DataCustomer> list = new ArrayList<>();
            for (String str : ids) {
                DataCustomer dataCustomer = new DataCustomer();
                dataCustomer.setCustomerId(str);
                list.add(dataCustomer);
            }
            tableDetail.setListCustomer(list);
        }
        if (StringUtils.isNotBlank(tableDetail.getColumnModular())) {
            List<String> ids = JSONArray.parseArray(tableDetail.getColumnModular(), String.class);
            List<DataModular> list = new ArrayList<>();
            for (String str : ids) {
                DataModular dataModular = new DataModular();
                dataModular.setModularId(str);
                list.add(dataModular);
            }
            tableDetail.setListModular(list);
        }
        if (StringUtils.isNotBlank(tableDetail.getColumnName())) {
            tableDetail.setColumnName(tableDetail.getColumnName().toUpperCase());
        }
        return tableDetail;
    }


    /**
     * 类型，机构等中文的转换
     *
     * @param list
     * @return
     * @throws Exception
     */
    public List<TableDetail> switchedListReportDetail(List<TableDetail> list) throws Exception {
        if (CollectionUtils.isEmpty(list)) {
            return list;
        }
        //字段类型
        Map<String, String> mapColumnType = dicvalueService.getCacheDicValueMap(ReportWorldEnum.COLUMN_TYPE.getCode());
        // 状态
        Map<String, String> mapStatus = dicvalueService.getCacheDicValueMap(ReportWorldEnum.REPORT_STATUS.getCode());
        //表所在分层
        Map<String, String> mapTableLayered = dicvalueService.getCacheDicValueMap(ReportWorldEnum.REPORT_TABLE_LAYERED.getCode());
        // 表类型
        Map<String, String> mapFtype = dicvalueService.getCacheDicValueMap(ReportWorldEnum.REPORT_TABLE_FTYPE.getCode());
        // 表来源
        Map<String, String> maptFsource = dicvalueService.getCacheDicValueMap(ReportWorldEnum.REPORT_TABLE_FSOURCE.getCode());

        for (TableDetail tableDetail : list) {
            if (null == tableDetail) {
                continue;
            }
            // 字段类型
            if (null != mapColumnType && mapColumnType.containsKey(String.valueOf(tableDetail.getColumnType()))) {
                tableDetail.setStrColumnType(mapColumnType.get(String.valueOf(tableDetail.getColumnType())));
            }
            //状态
            if (null != mapStatus && mapStatus.containsKey(String.valueOf(tableDetail.getStatus()))) {
                tableDetail.setStrStatus(mapStatus.get(String.valueOf(tableDetail.getStatus())));
            }
            //报表世界所在分层
            if (null != mapTableLayered && mapTableLayered.containsKey(String.valueOf(tableDetail.getLayered()))) {
                tableDetail.setLayered(mapTableLayered.get(tableDetail.getLayered()));
            }
            //表类型
            if (null != mapFtype && mapFtype.containsKey(String.valueOf(tableDetail.getFtype()))) {
                tableDetail.setFtype(mapFtype.get(tableDetail.getFtype()));
            }
            //表来源
            if (null != maptFsource && maptFsource.containsKey(String.valueOf(tableDetail.getFsource()))) {
                tableDetail.setFsource(maptFsource.get(tableDetail.getFsource()));
            }
            // 所属模块
            tableDetail.setColumnModular("");
            if (!CollectionUtils.isEmpty(tableDetail.getListModular())) {
                StringBuffer modularId = new StringBuffer();
                StringBuffer modularName = new StringBuffer();
                for (DataModular dataModular : tableDetail.getListModular()) {
                    modularId.append(dataModular.getModularId()).append(",");
                    modularName.append(dataModular.getModularName()).append("/");
                }
                tableDetail.setStrColumnModular(modularName.deleteCharAt(modularName.length() - 1).toString());
                tableDetail.setColumnModular(modularId.deleteCharAt(modularId.length() - 1).toString());
            }
            // 所属客户
            tableDetail.setColumnCustomer("");
            if (!CollectionUtils.isEmpty(tableDetail.getListCustomer())) {
                StringBuffer customeId = new StringBuffer();
                StringBuffer customeName = new StringBuffer();
                for (DataCustomer dataCustomer : tableDetail.getListCustomer()) {
                    customeId.append(dataCustomer.getCustomerId()).append(",");
                    customeName.append(dataCustomer.getCustomerName()).append("/");
                }
                tableDetail.setStrColumnCustomer(customeName.deleteCharAt(customeName.length() - 1).toString());
                tableDetail.setColumnCustomer(customeId.deleteCharAt(customeId.length() - 1).toString());
            }
            // 所属报表
            tableDetail.setColumnReport("");
            if (!CollectionUtils.isEmpty(tableDetail.getListReport())) {
                StringBuffer reportId = new StringBuffer();
                StringBuffer reportName = new StringBuffer();
                for (DataReport dataReport : tableDetail.getListReport()) {
                    reportId.append(dataReport.getReportId()).append(",");
                    reportName.append(dataReport.getReportName()).append("/");
                }
                tableDetail.setStrColumnReport(reportName.deleteCharAt(reportName.length() - 1).toString());
                tableDetail.setColumnReport(reportId.deleteCharAt(reportId.length() - 1).toString());
            }
        }
        return list;
    }

    /**
     * 新增报表字段信息
     *
     * @param tableDetail
     * @throws Exception
     */
    @Transactional
    public void addReportTableDetail(TableDetail tableDetail) throws Exception {
        if (null == tableDetail) {
            throw new BusinessException("获取删除报表世界表结构信息失败，请稍后重试！");
        }
        if (StringUtils.isNotBlank(tableDetail.getColumnName())) {
            tableDetail.setColumnName(tableDetail.getColumnName().toUpperCase());
        }
        tableDetail.setStatus(ReportWorldStatusEnum.REPORT_NORMAL.getCode());
        tableDetail.setAddUser(redisCacheManager.getLoginUserInfo().getLoginId());
        tableDetail.setId(DateUtil.generateUUID());
        tableDetail.setAddTime(LocalDateTime.now());
        // 默认值处理
        tableDetail.setColumnDefault(this.getColumnDefault(tableDetail.getColumnDefault()));
        this.addTableDetailInfo(tableDetail);
        // 查询最大序号
        QueryWrapper<TableDetail> wrapper = new QueryWrapper<>();
        wrapper.select("MAX(SEQUENCE) AS SEQUENCE");
        wrapper.eq("TABLE_ID", tableDetail.getTableId());
        TableDetail detail = this.getOne(wrapper);
        Integer sequence = 1;
        if (null != detail && null != detail.getSequence()) {
            sequence = detail.getSequence() + 1;
        }
        tableDetail.setSequence(sequence);
        tableDetailStandardCheckService.tableDetailStandardCheckInfo(tableDetail);
        this.save(tableDetail);
        // 新增对应关系表的对应字段也相应修改
        this.updateForeignTable(tableDetail);
        // 修改之前的字段状态为以删除
        this.updateOriginalColumName(tableDetail, ReportWorldStatusEnum.REPORT_DELETED.getCode());
    }

    /**
     * 获取表字段信息的时候默认值的处理
     *
     * @param defaultValue
     * @return
     */
    public String getColumnDefault(String defaultValue) {
        if (StringUtils.isBlank(defaultValue)) {
            return null;
        }
        // 默认值存放的是json格式
        List<TableColumnDefaultVO> list = new ArrayList<>();
        TableColumnDefaultVO vo = new TableColumnDefaultVO();
        vo.setFtype("COMMON");
        if (StringUtil.oneOf(defaultValue, "sys_guid,SYS_GUID,to_char,TO_CHAR,to_timestamp," +
                "TO_TIMESTAMP,sysdate,SYSDATE,TO_DATE,to_date")) {
            vo.setFtype("ORACLE");
        }
        vo.setFvalue(defaultValue.toUpperCase());
        list.add(vo);
        return JSONObject.toJSONString(list);
    }

    /**
     * 保存表字段对应的客户，模块，报表信息
     *
     * @param tableDetail
     * @throws Exception
     */
    private void addTableDetailInfo(TableDetail tableDetail) throws Exception {
        if (StringUtils.isNotBlank(tableDetail.getStrColumnCustomer())) {
            List<String> ids = JSONArray.parseArray(tableDetail.getStrColumnCustomer(), String.class);
            List<DataCustomer> list = new ArrayList<>();
            for (String str : ids) {
                DataCustomer dataCustomer = new DataCustomer();
                dataCustomer.setId(DateUtil.generateUUID());
                dataCustomer.setCustomerId(str);
                dataCustomer.setDataId(tableDetail.getId());
                dataCustomer.setDataCode(ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
                list.add(dataCustomer);
            }
            dataCustomerService.saveBatch(list);
        }
        if (StringUtils.isNotBlank(tableDetail.getStrColumnModular())) {
            List<String> ids = JSONArray.parseArray(tableDetail.getStrColumnModular(), String.class);
            List<DataModular> list = new ArrayList<>();
            for (String str : ids) {
                DataModular tableModular = new DataModular();
                tableModular.setId(DateUtil.generateUUID());
                tableModular.setModularId(str);
                tableModular.setDataId(tableDetail.getId());
                tableModular.setDataCode(ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
                list.add(tableModular);
            }
            dataModularService.saveBatch(list);
        }
        if (StringUtils.isNotBlank(tableDetail.getStrColumnReport())) {
            List<String> ids = JSONArray.parseArray(tableDetail.getStrColumnReport(), String.class);
            List<DataReport> list = new ArrayList<>();
            for (String str : ids) {
                DataReport tableReport = new DataReport();
                tableReport.setId(DateUtil.generateUUID());
                tableReport.setReportId(str);
                tableReport.setDataId(tableDetail.getId());
                tableReport.setDataCode(ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
                list.add(tableReport);
            }
            dataReportService.saveBatch(list);
        }
    }

    /**
     * 修改报表字段信息
     *
     * @param tableDetail
     * @throws Exception
     */
    @Transactional
    public void updateReportTableDetail(TableDetail tableDetail) throws Exception {
        if (null == tableDetail) {
            throw new BusinessException("获取删除报表世界表结构信息失败，请稍后重试！");
        }
        if (StringUtils.isNotBlank(tableDetail.getColumnName())) {
            tableDetail.setColumnName(tableDetail.getColumnName().toUpperCase());
        }
        tableDetail.setEditTime(LocalDateTime.now());
        tableDetailStandardCheckService.tableDetailStandardCheckInfo(tableDetail);
        //获取修改前的关联表和字段信息
        QueryWrapper<TableDetail> wrapper2 = new QueryWrapper<>();
        wrapper2.eq("COLUMN_NAME", tableDetail.getColumnName());
        wrapper2.eq("TABLE_ID", tableDetail.getTableId());
        TableDetail detail = this.getOne(wrapper2);
        this.updateById(tableDetail);
        //删除表和客户信息关联关系
        QueryWrapper<DataCustomer> wrapperCustomer = new QueryWrapper<>();
        wrapperCustomer.eq("DATA_ID", tableDetail.getId());
        wrapperCustomer.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
        dataCustomerService.remove(wrapperCustomer);
        //删除表和模块信息关联关系
        QueryWrapper<DataModular> wrapperModular = new QueryWrapper<>();
        wrapperModular.eq("DATA_ID", tableDetail.getId());
        wrapperModular.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
        dataModularService.remove(wrapperModular);
        //删除表和报表信息关联关系
        QueryWrapper<DataReport> wrapperReport = new QueryWrapper<>();
        wrapperReport.eq("DATA_ID", tableDetail.getId());
        wrapperReport.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
        dataReportService.remove(wrapperReport);
        // 保存对应关系信息
        this.addTableDetailInfo(tableDetail);
        // 新增对应关系表的对应字段也相应修改
        this.updateForeignTable(tableDetail);
        // 修改之前的字段状态为以删除
        this.updateOriginalColumName(tableDetail, ReportWorldStatusEnum.REPORT_DELETED.getCode());
    }

    /**
     * 新增和修改表字段信息的时候，设置的和其它表关联关系，同步新增和修改
     *
     * @throws Exception
     */
    private void updateForeignTable(TableDetail tableDetail) throws Exception {
        if (StringUtils.isBlank(tableDetail.getForeignTable()) || StringUtils.isBlank(tableDetail.getForeignTableColumn())) {
            return;
        }
        // 表名
        String tableName = tableDetail.getForeignTable();
        //字段名
        String columnName = tableDetail.getForeignTableColumn();
        //查询对应表信息
        QueryWrapper<Table> wrapper = new QueryWrapper<>();
        wrapper.eq("NAME", tableName);
        Table table = tableService.getOne(wrapper);
        if (null == table || StringUtils.isBlank(table.getId())) {
            return;
        }
        // 查询表的字段信息修改
        QueryWrapper<TableDetail> wrapper2 = new QueryWrapper<>();
        wrapper2.eq("COLUMN_NAME", columnName);
        wrapper2.eq("TABLE_ID", table.getId());
        TableDetail detail = this.getOne(wrapper2);
        // 关联表名为当前新增的表的名称
        //查询对应表信息
        QueryWrapper<Table> wrapper3 = new QueryWrapper<>();
        wrapper3.eq("ID", tableDetail.getTableId());
        Table tableAdd = tableService.getOne(wrapper3);
        detail.setForeignTable(tableAdd.getName());
        //关联字段为当前新增的字段名称
        detail.setForeignTableColumn(tableDetail.getColumnName());
        this.updateById(detail);
    }

    /**
     * 增加修改前字段信息的时候，以前的字段状态标识为已删除状态
     *
     * @param tableDetail
     * @throws Exception
     */
    private void updateOriginalColumName(TableDetail tableDetail, Integer status) throws Exception {
        if (null == tableDetail || StringUtils.isBlank(tableDetail.getTableId()) || StringUtils.isBlank(tableDetail.getOriginalColumName())) {
            return;
        }
        // 查询以前字段的信息修改状态
        QueryWrapper<TableDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("COLUMN_NAME", tableDetail.getOriginalColumName());
        wrapper.eq("TABLE_ID", tableDetail.getTableId());
        TableDetail detail = this.getOne(wrapper);
        if (null == detail || StringUtils.isBlank(detail.getId())) {
            throw new BusinessException("获取修改前表字段信息失败，请稍后重试！");
        }
        detail.setEditUser(redisCacheManager.getLoginUserInfo().getLoginId());
        detail.setEditTime(LocalDateTime.now());
        detail.setStatus(status);
        this.updateById(detail);
    }

    /**
     * 删除表字段信息
     *
     * @param id
     * @throws Exception
     */
    @Transactional
    public void delReportTableDetail(String id) throws Exception {
        if (StringUtils.isBlank(id)) {
            throw new BusinessException("获取删除报表世界表结构信息失败，请稍后重试！");
        }
        List<String> ids = JSONArray.parseArray(id, String.class);
        this.removeByIds(ids);

        //删除表和客户信息关联关系
        QueryWrapper<DataCustomer> wrapperCustomer = new QueryWrapper<>();
        wrapperCustomer.in("DATA_ID", ids);
        wrapperCustomer.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
        dataCustomerService.remove(wrapperCustomer);
        //删除表和模块信息关联关系
        QueryWrapper<DataModular> wrapperModular = new QueryWrapper<>();
        wrapperModular.in("DATA_ID", ids);
        wrapperModular.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
        dataModularService.remove(wrapperModular);
        //删除表和报表信息关联关系
        QueryWrapper<DataReport> wrapperReport = new QueryWrapper<>();
        wrapperReport.in("DATA_ID", ids);
        wrapperReport.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
        dataReportService.remove(wrapperReport);
    }

    /**
     * 批量修改表字段信息
     *
     * @param tableDetail
     * @param ids
     */
    @Transactional
    public void batchUpdateTableInfoDetail(TableDetail tableDetail, String ids) throws Exception {
        try {
            if (null == tableDetail || StringUtils.isBlank(ids)) {
                throw new BusinessException("获取批量修改数据信息失败，请稍后重试！");
            }
            List<String> listId = JSONArray.parseArray(ids, String.class);
            if (CollectionUtils.isEmpty(listId)) {
                throw new BusinessException("获取批量修改数据信息失败，请稍后重试！");
            }
            for (String id : listId) {
                if (StringUtils.isBlank(id)) {
                    continue;
                }
                tableDetail.setId(id);
                // 批量修改了对应的模块 客户 报表，就先删除在插入
                if (StringUtils.isNotBlank(tableDetail.getStrColumnCustomer())) {
                    //删除表和客户信息关联关系
                    QueryWrapper<DataCustomer> wrapperCustomer = new QueryWrapper<>();
                    wrapperCustomer.in("DATA_ID", tableDetail.getId());
                    wrapperCustomer.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
                    dataCustomerService.remove(wrapperCustomer);
                }
                if (StringUtils.isNotBlank(tableDetail.getStrColumnModular())) {
                    //删除表和模块信息关联关系
                    QueryWrapper<DataModular> wrapperModular = new QueryWrapper<>();
                    wrapperModular.in("DATA_ID", tableDetail.getId());
                    wrapperModular.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
                    dataModularService.remove(wrapperModular);
                }
                if (StringUtils.isNotBlank(tableDetail.getStrColumnReport())) {
                    //删除表和报表信息关联关系
                    QueryWrapper<DataReport> wrapperReport = new QueryWrapper<>();
                    wrapperReport.in("DATA_ID", tableDetail.getId());
                    wrapperReport.eq("DATA_CODE", ReportWorldEnum.REPORT_TABLE_DETAIL_CODE.getCode());
                    dataReportService.remove(wrapperReport);
                }
                this.addTableDetailInfo(tableDetail);  // 保存表字段对应的客户，模块，报表信息
                TableDetail detail = new TableDetail();
                UpdateWrapper<TableDetail> wrapper = new UpdateWrapper<>();
                wrapper.eq("ID", id);
                boolean falg = false;
                if (StringUtils.isNotBlank(tableDetail.getColumnName())) {
                    detail.setColumnName(tableDetail.getColumnName());
                    falg = true;
                }
                if (StringUtils.isNotBlank(tableDetail.getColumnChineseName())) {
                    detail.setColumnChineseName(tableDetail.getColumnChineseName());
                    falg = true;
                }
                if (null != tableDetail.getColumnType()) {
                    detail.setColumnType(tableDetail.getColumnType());
                    falg = true;
                }
                if (null != tableDetail.getPrimaryKey()) {
                    detail.setPrimaryKey(tableDetail.getPrimaryKey());
                    falg = true;
                }
                if (null != tableDetail.getBusinessPrimaryKey()) {
                    detail.setBusinessPrimaryKey(tableDetail.getBusinessPrimaryKey());
                    falg = true;
                }
                if (null != tableDetail.getColumnLength()) {
                    detail.setColumnLength(tableDetail.getColumnLength());
                    falg = true;
                }
                if (null != tableDetail.getColumnDecimal()) {
                    detail.setColumnDecimal(tableDetail.getColumnDecimal());
                    falg = true;
                }
                if (StringUtils.isNotBlank(tableDetail.getColumnDescribe())) {
                    detail.setColumnDescribe(tableDetail.getColumnDescribe());
                    falg = true;
                }
                if (null != tableDetail.getColumnNull()) {
                    detail.setColumnNull(tableDetail.getColumnNull());
                    falg = true;
                }
                if (StringUtils.isNotBlank(tableDetail.getColumnDefault())) {
                    detail.setColumnDefault(tableDetail.getColumnDefault());
                    falg = true;
                }
                if (StringUtils.isNotBlank(tableDetail.getVersion())) {
                    detail.setVersion(tableDetail.getVersion());
                    falg = true;
                }
                if (StringUtils.isNotBlank(tableDetail.getCodeName())) {
                    detail.setCodeName(tableDetail.getCodeName());
                    falg = true;
                }
                if (null != tableDetail.getStatus()) {
                    detail.setStatus(tableDetail.getStatus());
                    falg = true;
                }
                if (falg) {
                    detail.setEditUser(redisCacheManager.getLoginUserInfo().getLoginId());
                    detail.setEditTime(LocalDateTime.now());
                    this.update(detail, wrapper);
                }
            }
        } catch (Exception ex) {
            log.error(ex.getMessage());
            throw new BusinessException("批量修改表明细信息出错！" + ex.getMessage());
        }
    }


}
